package com.javabasic.algorithm.leetcode;

import java.util.Scanner;

/**
 * @Author xiongmin
 * @ClassName 合唱队形
 * @Description TODO
 * @Date 2019/8/31 15:49
 * @Version 1.0
 **/
public class 合唱队形 {

    static Scanner cin = new Scanner(System.in);

    static int[] arr = null;
    static int result = Integer.MAX_VALUE, len;
    public static void main(String[] args) {
        int n = cin.nextInt();
        arr = new int[n];
        len = 0;
        for (int i = 0; i < n; i++) {
            arr[len] = cin.nextInt();
            if (i > 0 && arr[i] == arr[i-1]) {
            } else {
                len++;
            }
        }
        dfs(0,0,"");
        System.out.println(result + n-len);
//        System.out.println(len);
    }

    private static void dfs(int index, int num, String str) {
        if (num >= result) return;
        if (result == 0) return;
        if (index == len) {
            int flag = 1; // 1 表示是 up  2 表示是 down
            int preNum = 0;
            boolean tag = true;
            boolean isSuccess = true;
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) == '1') {
                    if (tag) {
                        preNum = arr[i];
                        tag = false;
                    } else {
                        if (arr[i] > preNum && flag == 1) {
                            preNum = arr[i];
                        } else if (arr[i] < preNum) {
                            preNum = arr[i];
                            flag ++;
                        } else {
                            isSuccess = false;
                            break;
                        }
                    }
                }
            }
            if (isSuccess) {
                result = num;
            }
            return;
        }
        dfs(index+1,num+1,str+"0"); // index 出队
        dfs(index+1,num,str+"1"); // index 不出队

    }

}
/*
20
186 186 150 200 160 130 197 220 186 186 150 200 160 130 197 220 160 130 197 220
 */